package umt.cs.cs241.assignment3b.c_3_15;

import java.util.Random;

public class RecursiveMinMax {

	private int min;
	private int max;
	
	private int [] values;
	private int arraySize;
	
	public RecursiveMinMax(){
		
		arraySize = 20;
		values = this.getRandomIntArray(arraySize);
		this.getMinMax(0);
		this.print();
	}
	
	private void getMinMax(int index){
		
		//Set 'min' and 'max' to the first element of the array
		if(index == 0){
			min = values[index];
			max = values[index];
		}
		
		if(index < values.length){
			
			//Determine min
			if(values[index] < min){
				min = values[index];
			}
			
			//Determin max
			if(values[index] > max){
				max = values[index];
			}
			
			index++;
			
			this.getMinMax(index);
		}
		
	}
	
	private void print(){
		
		for(int i = 0; i < values.length; i++){
			System.out.print(values[i] + " ");
		}
		
		System.out.println();
		System.out.println("Minimum Value: " + min);
		System.out.println("Maximum Value: " + max);
	}
	
	/**
	 * Returns an array of random int values with an array size specified by the user.
	 * 
	 * @param arraySize The number of values a user wishes to place in the returned array.
	 * @return randomNumbers An array of random number values
	 */
	private int[] getRandomIntArray(int arraySize){
		
		Random randomGen = new Random();
		
		int [] randomNumbers = new int[arraySize];
		
		for(int i = 0; i < (arraySize - 1); i++){
			randomNumbers[i] = randomGen.nextInt(500) + 1;
		}
		
		return randomNumbers;
		
	}
	
}
